/**
 * This file is part of codzo-freelance-timetracking.
 * 
 * codzo-freelance-timetracking is free software: you can
 * redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your
 * option) any later version.
 * 
 * codzo-freelance-timetracking is distributed in the
 * hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
 * Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with codzo-freelance-timetracking. If not, see
 * <http://www.gnu.org/licenses/>.
 */
#include <wx/webview.h>
#include <wx/xrc/xmlres.h>

#include "main/constants.h"
#include "main/timetracker.h"
#include "main/browserwindow.h"
#include "icons/app.ico-16.xpm"

IMPLEMENT_APP(TimeTracker)

bool TimeTracker::OnInit()
{
    /* initialize random seed: */
    srand ( time(NULL) );
    setlocale(LC_ALL,"");

    // wxWidgets has a bug that first call to wxDateTime::Format will ignore the timezone
    // setting. Call here once for allignment
    wxDateTime::Today().Format(DATETIME_FORMAT_DATE);
 
    // Display taskbar icon
    MainTaskBarIcon * taskbaricon = new MainTaskBarIcon();
    taskbaricon->SetIcon(app_ico_xpm_16);
	m_taskbaricon = taskbaricon ;

	MainBrowserWindow * browser = new MainBrowserWindow(NULL);
	browser->Show();
	
	m_mainWindow = browser ;

    return true ;
}

TimeTracker::~TimeTracker()
{
}

void TimeTracker::ShowMainWindow(bool show)
{
	if(show)
	{
		m_mainWindow->Show();
	}
	else
	{
		m_mainWindow->Hide();
	}
}

int  TimeTracker::OnExit()
{
	m_mainWindow->Destroy();

	if(m_taskbaricon)
	{
		m_taskbaricon->Destroy();
	}
    return 0 ;
}

void TimeTracker::ExitApplication()
{
	ExitMainLoop();
}

